import numpy as np
import pandas as pd
import pandas as pd
import numpy as np
import re
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
import statsmodels.api as sm
import math
from scipy.optimize import brentq
bmi = -1

def convert_to_p(week,target):

    p = 5.6231+0.0328*week-0.1335*bmi
    #print(p)
    p = 1.0/(1+math.exp(-p))-target
    #print(p)
    return p

df = pd.read_excel('data_after_q2_2_noisy.xlsx')


for i in range(len(df)):

    bmi = df['基准BMI'][i]

    ans =  brentq(convert_to_p, -40,100, args=(0.875,))

    print(ans)

    df.loc[i,'t90'] = ans

print(df)
df.to_excel('data_after_q2_2_noisy_2.xlsx')
